extensions.org.icongarden.http.writeASCII ("Content-type: text/html\r\n\r\n");
var writeUTF8 = extensions.org.icongarden.http.writeUTF8;

try
{
	var fs = extensions.org.icongarden.fileSystem;

	try
	{
		var workingDirectory = fs.getWorkingDirectory ( );
		writeUTF8 ('<p>working directory as array</p>');
		writeUTF8 ('<p>' + workingDirectory + '</p>');
	}
	catch (e)
	{
		writeUTF8 ('could not log working directory as array:' + e);
	}

	writeUTF8 ('<hr>');

	try
	{
		workingDirectory [workingDirectory.length] = "counterpart";
		fs.setWorkingDirectory (workingDirectory);
		writeUTF8 ('<p>after setting working directory with longer full path</p>');
		writeUTF8 ('<p>' + extensions.org.icongarden.env.get ("PWD") + '</p>');
	}
	catch (e)
	{
		writeUTF8 ('could not set working directory with longer full path: ' + e);
	}

	writeUTF8 ('<hr>');

	try
	{
		workingDirectory.length -= 1;
		fs.setWorkingDirectory (workingDirectory);
		writeUTF8 ('<p>after setting working directory with shorter full path</p>');
		writeUTF8 ('<p>' + extensions.org.icongarden.env.get ("PWD") + '</p>');
	}
	catch (e)
	{
		writeUTF8 ('could not set working directory with shorter full path: ' + e);
	}

	writeUTF8 ('<hr>');

	try
	{
		fs.setWorkingDirectory (["counterpart"]);
		writeUTF8 ('<p>after setting working directory with relative path</p>');
		writeUTF8 ('<p>' + extensions.org.icongarden.env.get ("PWD") + '</p>');
	}
	catch (e)
	{
		writeUTF8 ('could not set working directory with relative path: ' + e);
	}

	writeUTF8 ('<hr>');

	workingDirectory = fs.getWorkingDirectory ( );

	function traverse (directoryEntries)
	{
		writeUTF8 ('<ul>');
		for (var directoryEntryIndex in directoryEntries)
		{
			var directoryEntry = directoryEntries [directoryEntryIndex];
			writeUTF8 ("<li>'" + directoryEntry.name + "' is a " + directoryEntry.type + " whose inode is " + directoryEntry.inode + "</li>");
	
			if (directoryEntry.type == 'directory')
			{
				writeUTF8 ('<blockquote>');
				traverse (directoryEntry.children);
				writeUTF8 ('</blockquote>');
			}
		}
		writeUTF8 ('</ul>');
	}
	
	traverse (fs.enumerateDirectory (workingDirectory));
	writeUTF8 ('<hr>');
	traverse (fs.enumerateDirectory (workingDirectory,false));
	writeUTF8 ('<hr>');
	traverse (fs.enumerateDirectory (workingDirectory,true));
}
catch (e)
{
	writeUTF8 (e);
}
